//
//  WbTabBarViewController.swift
//  Weibo
//
//  Created by HH on 16/11/30.
//  Copyright © 2016年 Weibo. All rights reserved.
//

import UIKit

class WbTabBarViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupUI()
        // Do any additional setup after loading the view.
    }
    
    private func setupUI(){
        
        let wbTabBar = WbTabBar()
        
        wbTabBar.callBack = { [weak self]  in
            
            print("加号按钮")
            
            let composeView = WbComposeView()
    
            if let weakSelf = self {
                //调用自身的show方法,使自身被添加到控制器上
                composeView.show(target: weakSelf)
            }
            
        }
        
        setValue(wbTabBar, forKey: "tabBar")
        
        addChildViewController(childController: WbHomeController(), title: "首页", imageName: "tabbar_home")
        
        addChildViewController(childController: WbMessageController(), title: "消息", imageName: "tabbar_message_center")
        
        addChildViewController(childController: WbDiscoverController(), title: "发现", imageName: "tabbar_discover")
        
        addChildViewController(childController: WbProfileController(), title: "我", imageName: "tabbar_profile")
        
//        selectedIndex = 2
        
        
    }
    
    
    //MARK:添加子控制器
    func addChildViewController(childController: UIViewController,title:String,imageName:String) {
        childController.title = title
      
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orange], for: .selected)
        
//        childController.view.backgroundColor = UIColor.white
        
        childController.tabBarItem.image = UIImage(named: imageName)?.withRenderingMode(.alwaysOriginal)
        
        childController.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.withRenderingMode(.alwaysOriginal)
        
        let navController = WbNavigationController(rootViewController: childController)
        
        addChildViewController(navController)
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
